#ifndef __PHIDGETMANAGER_H__
#define __PHIDGETMANAGER_H__

#ifdef __APPLE__
 #import <Phidget21/phidget21.h>
#else
#endif
#include <list>
#include <string>
#include <map>


class Phidget;
class PhidgetPropertyAlias;
class MonkeyContext;
class MonkeyRuntime;


class PhidgetManager
{
  private:
	std::string				*_serverID, *_address, *_password;
	int						_port;
  	MonkeyContext *translateContext;
  	std::map<std::string, PhidgetPropertyAlias> propertyAliases;
	CPhidgetManagerHandle	managerHandle;
	std::list<Phidget *>	*devices;
	
	void CommonConstruct(MonkeyRuntime *rt);
	
  public:
	PhidgetManager(MonkeyRuntime *rt);
	PhidgetManager(MonkeyRuntime *rt, const char *serverID, const char *password);
	PhidgetManager(MonkeyRuntime *rt, const char *address, int port, const char *password);
	~PhidgetManager();
	
	bool OpenPhidgetHandle(CPhidgetHandle handle, int serial);
	
	void PhidgetDidAttach(CPhidgetHandle handle);
	void PhidgetDidDetach(CPhidgetHandle handle);

	const std::list<Phidget *> AttachedDevices();
	Phidget *FindDeviceByID(int serial);
  	void RegisterPropertyAlias(PhidgetPropertyAlias alias);
  	std::string ParsePropertyName(std::string property, std::string &hostID, Phidget **device, std::string &translator);

	void PhidgetValueChanged(Phidget *phidget, std::string valueName, std::string newValue);
  	std::string GetPropertyValue(std::string property);
  	void SetPropertyValue(std::string property, std::string value);
};

#endif /* __PHIDGETMANAGER_H__ */

